from time import sleep
import unittest
from case.selenium_test.TestDemo import TestDemo
#安装数据驱动
from ddt import ddt,data,unpack

def read_file():
    file = open("params.txt","r",encoding="utf8")
    li =[]
    for line in file.readlines():
        li.append(line.strip('\n').split(','))
    file.close()
    return li

@ddt
class baiDuTestCase1(unittest.TestCase):
    #每个用例方法之前运行
    def setUp(self):
        self.tk = TestDemo("https://afterwin.cn/login", "chrome")
        print("开始执行测试用例")


    #测试用例的执行顺序是根据用例名称来顺序执行的
    '''
    一个参数的传法
    @data("虚竹","selenium")
    两个参数的传法:通过集合的方式传入， 如果不加入unpack解包，'id','虚竹'会作为一个参数传入locator。
    * 表示基于元祖的形式处理，**表示基于字典以键值对的形式处理
    '''

    @data(*read_file())
    @unpack
    def test_login(self, locatior, username, password):  # 测试用例的名称要以test开头
        print(username)
        print(password)
        self.tk.input_text(locatior, "userName", username)
        self.tk.input_text(locatior, "passWord", password)
        self.tk.click_element("css_selector", "button[type='submit']")
        sleep(2)


    '''
    @data(['id','fandanping', 'fandanping521'])
    @unpack
    def test_1(self, locatior, username,password):  # 测试用例的名称要以test开头
        self.tk.input_text(locatior, "userName", username)
        self.tk.input_text(locatior, "passWord", password)
        self.tk.click_element("css_selector", "button[type='submit']")
        sleep(2)
    '''
    '''
    @data(['id','虚竹'],['id','selenium'])
    @unpack
    def test_1(self,locatior,input_value):  #测试用例的名称要以test开头
        self.tk.input_text(locatior,"kw",input_value)
        self.tk.click_element("id","su")
        sleep(2)
    '''
    '''
    def test_2(self):
        self.tk.input_text("id", "kw", "selenium")
        self.tk.click_element("id", "su")
        sleep(2)
    '''

    #每个用例方法之后执行
    def tearDown(self):
        self.tk.close_brower()
        print("一条测试用例执行完毕")

if __name__ =='__main__':  #运行主函数
        unittest.main()

